// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Eggman Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 73 : TYPE_EGGMAN


// Static Values

// Tables

event ObjectMain
	switch object.state
	case 0
		temp0 = object.xpos
		temp0 -= 0x880000
		if object[0].xpos >= temp0
			object.state++
			object.value0 = 180
			object.animation = 1
		end if
		break
	case 1
		object.value0--
		if object.value0 < 0
			object.state++
			object.value0 = 15
			object.animation = 2
		end if
		break
	case 2
		object.value0--
		if object.value0 < 0
			object.state++
			object.xvel = -0xFC00
			object.yvel = -0x3C000
		end if
		break
	case 3
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.yvel += 0x2400
		if object.yvel == 0
			object.animation = 1
			object.state++
		end if
		break
	case 4
		object.animation = 1
		object.state++
		break
	end switch
	switch object.animation
	case 0
		object.frame = 0
		break
	case 1
		object.animationTimer++
		if object.animationTimer == 14
			object.animationTimer = 0
		end if
		object.frame = object.animationTimer
		object.frame /= 7
		object.frame++
		break
	case 2
		if object.yvel == 0
			object.frame = 3
		else
			object.frame = 4
		end if
		break
	case 3
		if object.yvel == 0
			object.frame = 5
		else
			object.frame = 6
		end if
		break
	end switch
	if object.value1 != 0
		object.value1--
	end if
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -14, -20, 14, 16, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			if object.value1 == 0
				CallFunction(PlayerObject_CheckHit)
				if checkResult == 1
					object.animation = 3
					object.value1 = 32
				else
					if object.yvel == 0
						object.animation = 1
					end if
				end if
			end if
		end if
	next
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	if saveRAM[495] == 0
		LoadSpriteSheet("SBZ/Objects.gif")
		SpriteFrame(-22, -23, 38, 51, 1, 209)
		SpriteFrame(-22, -24, 38, 52, 42, 208)
		SpriteFrame(-22, -23, 38, 51, 84, 209)
		SpriteFrame(-16, -16, 46, 44, 350, 165)	
		SpriteFrame(-16, -23, 46, 55, 350, 210)
		SpriteFrame(-22, -24, 42, 52, 225, 266)
		SpriteFrame(-30, -24, 60, 44, 289, 165)
		SpriteFrame(-24, -23, 54, 43, 236, 221)
		SpriteFrame(-21, -25, 51, 52, 269, 213)
		SpriteFrame(-22, -20, 42, 64, 225, 319)
	else
		LoadSpriteSheet("SBZ/Objects.gif")
		SpriteFrame(-22, -23, 32, 56, 1, 310)		//Idle
		SpriteFrame(-22, -24, 32, 56, 34, 310)		//Laught I
		SpriteFrame(-22, -23, 32, 56, 67, 310)		//Laught II
		SpriteFrame(-16, -16, 32, 46, 244, 159)		//Jump
		SpriteFrame(-16, -23, 32, 56, 189, 204)		//Run III
		SpriteFrame(-22, -24, 42, 52, 225, 266)		//Hit I
		SpriteFrame(-30, -24, 60, 44, 289, 165)		//Hit Jump
		SpriteFrame(-24, -23, 54, 43, 236, 221)		//Run I
		SpriteFrame(-21, -25, 51, 52, 269, 213)		//Run II
		SpriteFrame(-22, -20, 42, 64, 225, 319)		//Hit II
	endif
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
